package me.out1kiss.www.web.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import springfox.documentation.builders.*;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author hx
 */
@Configuration
public class Swagger3Config {

    @Bean
    public Docket createRestApi1() {
        RequestParameter requestParameter = new RequestParameterBuilder().name("token")
                .description("登陆token")
                .in(ParameterType.HEADER)
                .required(false)
                .build();
        Response response = new ResponseBuilder()
                .code("400")
                .description("测试")
                .isDefault(true)
                .build();
        return new Docket(DocumentationType.OAS_30)
                .globalRequestParameters(Collections.singletonList(requestParameter))
                .globalResponses(HttpMethod.GET, Collections.singletonList(response))
                .globalResponses(HttpMethod.PUT, new ArrayList<>())
                .groupName("api1")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api1Swagger.class))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApi2() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("api2")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api2Swagger.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger3接口文档")
                .description("更多请咨询服务开发者")
                .contact(new Contact("HX", "http://www.out1kiss.me", "345598716@qq.com"))
                .version("1.0")
                .build();
    }

}
